home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / ARCNET.C < prev    next >
Text File  |  1993-08-09  |  2KB  |  117 lines

  1. /* Stuff generic to all ARCnet controllers */
  2. #include "global.h"
  3. #include "config.h"
  4. #ifdef ARCNET
  5. #include "mbuf.h"
  6. #include "iface.h"
  7. #include "timer.h"
  8. #include "arp.h"
  9. #include "ip.h"
  10. #include "arcnet.h"
  11.  
  12. char ARC_bdcst[] = { 0 };
  13.  
  14. /* Convert ARCnet header in host form to network mbuf */
  15. static struct mbuf * near
  16. htonarc(struct arc *arc,struct mbuf *data)
  17. {
  18.     struct mbuf *bp = pushdown(data,ARCLEN);
  19.     char *cp = bp->data;
  20.  
  21.     memcpy(cp,arc->source,AADDR_LEN);
  22.     cp += AADDR_LEN;
  23.     memcpy(cp,arc->dest,AADDR_LEN);
  24.     cp += AADDR_LEN;
  25.     *cp = arc->type;
  26.  
  27.     return bp;
  28. }
  29.  
  30. /* Extract ARCnet header */
  31. int
  32. ntoharc(struct arc *arc,struct mbuf **bpp)
  33. {
  34.     pullup(bpp,arc->source,AADDR_LEN);
  35.     pullup(bpp,arc->dest,AADDR_LEN);
  36.     arc->type = PULLCHAR(bpp);
  37.  
  38.     return ARCLEN;
  39. }
  40.  
  41. /* Format an ARCnet address into a printable ascii string */
  42. char *
  43. parc(char *out,char *addr)
  44. {
  45.     sprintf(out,"%02x",uchar(addr[0]));
  46.     return out;
  47. }
  48.  
  49. /* Convert an ARCnet address from Hex/ASCII to binary */
  50. int
  51. garc(char *out,char *cp)
  52. {
  53.     *out = htoi(cp);
  54.     return 0;
  55. }
  56.  
  57. /* Send an IP datagram on ARCnet */
  58. int
  59. anet_send(
  60. struct mbuf *bp,        /* Buffer to send */
  61. struct iface *iface,    /* Pointer to interface control block */
  62. int32 gateway,            /* IP address of next hop */
  63. int prec,
  64. int del,
  65. int tput,
  66. int rel)
  67. {
  68.     char *agate;
  69.  
  70.     if((agate = res_arp(iface,ARP_ARCNET,gateway,bp)) != NULLCHAR)
  71.         return (*iface->output)(iface,agate,iface->hwaddr,ARC_IP,bp);
  72.     return 0;
  73. }
  74.  
  75. /* Send a packet with ARCnet header */
  76. int
  77. anet_output(
  78. struct iface *iface,    /* Pointer to interface control block */
  79. char *dest,                /* Destination ARCnet address */
  80. char *source,            /* Source ARCnet address */
  81. int16 type,                /* Type field */
  82. struct mbuf *data)        /* Data field */
  83. {
  84.     struct arc ap;
  85.     struct mbuf *bp;
  86.  
  87.     memcpy(ap.dest,dest,AADDR_LEN);
  88.     memcpy(ap.source,source,AADDR_LEN);
  89.     ap.type = type;
  90.  
  91.     bp = htonarc(&ap,data);
  92.     return (*iface->raw)(iface,bp);
  93. }
  94.  
  95. /* Process incoming ARCnet packets. Shared by all ARCnet drivers. */
  96. void
  97. aproc(struct iface *iface,struct mbuf *bp)
  98. {
  99.     struct arc hdr;
  100.  
  101.     /* Remove ARCnet header and kick packet upstairs */
  102.     ntoharc(&hdr,&bp);
  103.  
  104.     switch(uchar(hdr.type)){
  105.     case ARC_ARP:
  106.         arp_input(iface,bp);
  107.         break;
  108.     case ARC_IP:
  109.         ip_route(iface,NULLIF,bp,0);
  110.         break;
  111.     default:
  112.         free_p(bp);
  113.         break;
  114.     }
  115. }
  116.  
  117. #endif /* ARCNET */